package com.yunxi.service.dubboService.impl.vip;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.enums.DMSEnumsEntity;
import com.yunxi.core.util.WgrDate;
import com.yunxi.model.order.OrderCustomer;
import com.yunxi.model.vip.StoVehicleExp;
import com.yunxi.order.pojo.OrderActualSalesVO;
import com.yunxi.order.pojo.OrderCustomerVO;
import com.yunxi.sat.pojo.HandleVehicleVO;
import com.yunxi.service.localService.OrderActualSalesService;
import com.yunxi.service.localService.OrderCustomerService;
import com.yunxi.service.localService.sat.HandleVehicleService;
import com.yunxi.service.localService.vip.StoVehicleExpService;
import com.yunxi.vip.pojo.StoVehicleExpVO;
import com.yunxi.vip.pojo.VipManageVO;
import com.yunxi.vip.service.StoVehicleExpDubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * <p>
 * 体验车库存 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-09-25
 */
public class StoVehicleExpDubboServiceImpl implements StoVehicleExpDubboService {

    @Autowired
    @Qualifier(value = "stoVehicleExpServiceImpl")
    StoVehicleExpService stoVehicleExpService;

    @Autowired
    @Qualifier(value = "orderCustomerServiceImpl")
    OrderCustomerService orderCustomerService;

    @Autowired
    @Qualifier(value = "handleVehicleServiceImpl")
    HandleVehicleService handleVehicleService;

    @Autowired
    @Qualifier(value = "orderActualSalesServiceImpl")
    OrderActualSalesService orderActualSalesService;

    @Override
    public StoVehicleExpVO getById(String id) throws InvocationTargetException, IllegalAccessException {
    StoVehicleExp StoVehicleExp = stoVehicleExpService.getById(id);
    StoVehicleExpVO StoVehicleExpVO = new StoVehicleExpVO();
        BeanUtils.copyProperties(StoVehicleExp,StoVehicleExpVO);
        return StoVehicleExpVO;
    }

    @Override
    public void saveOrUpdate(StoVehicleExpVO StoVehicleExpVO) throws InvocationTargetException, IllegalAccessException {
        StoVehicleExp StoVehicleExp = new StoVehicleExp();
        BeanUtils.copyProperties(StoVehicleExpVO,StoVehicleExp);
        stoVehicleExpService.saveOrUpdate(StoVehicleExp);
    }

    @Override
    public void removeById(String id) {
        stoVehicleExpService.removeById(id);
    }

    @Override
    public PageInfo<StoVehicleExpVO> findPageByVO(StoVehicleExpVO StoVehicleExpVO, Integer pageNum, Integer pageSize) throws InvocationTargetException, IllegalAccessException {
      PageInfo<StoVehicleExpVO> pageInfo = stoVehicleExpService.pageByVo(StoVehicleExpVO,pageNum,pageSize);
      return pageInfo;
   }

    @Override
    public void removeByListVo(List<StoVehicleExpVO> StoVehicleExpVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
        stoVehicleExpService.removeByListVo(StoVehicleExpVOList);
    }

    @Override
    public List listByVo(StoVehicleExpVO StoVehicleExpVO) {
      return stoVehicleExpService.listByVo(StoVehicleExpVO);
    }

    @Override
    public StoVehicleExpVO getByCas(String expId) {
        return stoVehicleExpService.getByCas(expId);
    }

    @Override
    public int updateStatus(StoVehicleExpVO vo) {
        StoVehicleExp o = new StoVehicleExp();
        BeanUtils.copyProperties(vo,o);
        OrderCustomerVO ocv = orderCustomerService.getByOrderCustomerNo(vo.getOrderCustomerNo()) ;
        OrderCustomer oc = new OrderCustomer();
        if(vo.getHireStatus() == DMSEnumsEntity.HireStatus.UP.getCode()){
            //订单表开始时间更新

            HandleVehicleVO hv = handleVehicleService.getByOrderCustomerNo(vo.getOrderCustomerNo());
            if(hv!=null){
                BeanUtils.copyProperties(ocv,oc);
                oc.setHireStartDate(WgrDate.getCurrentDate());
                orderCustomerService.updateById(oc);
            }else{
                return 12998;
            }
        }else if(vo.getHireStatus() == DMSEnumsEntity.HireStatus.DOWN.getCode()){
            //订单表结束时间更新
            BeanUtils.copyProperties(ocv,oc);
            oc.setHireEndDate(WgrDate.getCurrentDate());
            orderCustomerService.updateById(oc);
        }

        stoVehicleExpService.saveOrUpdate(o);
        return 200;
    }

    @Override
    public PageInfo<StoVehicleExpVO> pageByCheckSales(StoVehicleExpVO stoVehicleExpVO, Integer pageNum, Integer pageSize) {
        PageInfo<StoVehicleExpVO> pageInfo = stoVehicleExpService.pageByCheckSales(stoVehicleExpVO,pageNum,pageSize);
        return pageInfo;
    }

    @Override
    public void checkSales(StoVehicleExpVO stoVehicleExpVO) {
        stoVehicleExpService.checkSales(stoVehicleExpVO);
    }

    @Override
    public PageInfo<HandleVehicleVO> pageHandleVehicle(VipManageVO vipApplyVO,Integer pageNum,Integer pageSize) {
        return handleVehicleService.pageByVip(vipApplyVO,pageNum,pageSize);
    }

    @Override
    public PageInfo<OrderActualSalesVO> pageActualSales(VipManageVO vipApplyVO,Integer pageNum,Integer pageSize) {
        return orderActualSalesService.pageByVip(vipApplyVO,pageNum,pageSize);
    }
}
